fix(identity): correct audiusSdk accessor in authMiddleware (.full.users -> .users)#14482
Merged
Conversation
|
7ed67a3 to
7838f7d
Compare
…ers -> .users)
authMiddleware backfills blockchainUserId/handle for users whose identity
row lacks them (the state of any guest / freshly signed-up user) by calling
the SDK. It used `req.app.get('audiusSdk').full.users.getUserAccount(...)`,
but the @audius/sdk instance has no `.full` namespace - `users` is a
top-level API. So `.full` is undefined and `.users` throws a synchronous
TypeError ("Cannot read properties of undefined (reading 'users')") on
EVERY new-user auth request (/users/update, /record_ip, etc).
Confirmed in prod logs:
TypeError: Cannot read properties of undefined (reading 'users')
at authMiddleware (build/src/authMiddleware.js:97:68)
msg: "Failed to update blockchainUserId/handle"
The bad accessor came in with the monorepo import (#14388) and only began
firing once #14474 (6/15) made loadAudiusSdk.cjs available so the SDK
actually initialized - matching the signup regression window. The
surrounding try/catch swallowed the error and called next(), so the
backfill silently never happened for new users.
Fix: use the correct accessor `audiusSdk.users.getUserAccount`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7838f7d to
91d317b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users report failing/janky signups, with
POST https://identityservice.audius.co/users/updatemisbehaving (Slack thread).authMiddleware(which gates/users/update,/record_ip, and every other authenticated endpoint) backfillsblockchainUserId/handlefor any identityUsersrow that lacks them — i.e. every guest / freshly signed-up user. It did this via:But the
@audius/sdkinstance has no.fullnamespace —usersis a top-level API (audiusSdk.users.getUserAccount). So.fullisundefinedand.usersthrows a synchronousTypeErroron every new-user auth request.Confirmed in prod logs:
The surrounding
try/catchswallowed it and callednext(), so the request proceeded but the backfill silently never happened — new identity rows never gotblockchainUserId/handleset.Why it started now
The bad accessor came in with the monorepo import of identity-service (#14388, 5/22), which rewrote
authMiddlewareto use@audius/sdk. It was dormant until #14474 (6/15) shippedloadAudiusSdk.cjsinto the build, so the SDK actually initialized and this line began firing — matching the regression window. (identity hadn't been deployed in a while; 6/15 was the first monorepo image promoted to prod.)I verified prod is in the benign config otherwise:
environment=productionis set inidentity-service-secret, so the SDK targets prod discovery — the issue is purely the wrong accessor, not SDK misconfig.Fix
Use the correct accessor
audiusSdk.users.getUserAccountin bothauthMiddlewareandparameterizedAuthMiddleware. One-token change per call site.Notes
record_iphunch is a red herring:/users/updatedoesn't callrecordIP. (Though/record_ipis also gated byauthMiddleware, so it hit the same TypeError — likely the source of the confusion.)src/data/disposable_email_blocklist.confat signup via an unguardedfs.readFileSync; that file wasn't copied into the build until fix(identity): copy loadAudiusSdk.cjs into build output #14474 (same one-liner that also addedloadAudiusSdk.cjs). Worth hardening that read separately.packages/libsmethods that hit them aren't called by any current client.Verification
getUserAccountlives on the top-levelUsersApi(audiusSdk.users) and there is no.fullin the SDK instance shape (@audius/sdkindex.d.ts).res.data.useris still correct (UserAccountResponse.data: Account,Account.user: User).environment=production.After deploy, the
TypeError ... reading 'users'log should disappear andFailed to update blockchainUserId/handleshould drop to near-zero.🤖 Generated with Claude Code